import React, { Component } from 'react';
import { Modal, Form, Input,Radio,Select,DatePicker,Popconfirm ,Row,Col,Button,Icon,Upload, message} from 'antd';
import styles from '../item.less';
import moment from 'moment'
import * as ContractModel from '../../model/contract';
import * as CustomerModel from '../../model/customer';
import * as UserModel from '../../model/user';
import * as  StockModel from '../../model/stock';

import 'moment/locale/zh-cn';
moment.locale('zh-cn');
const FormItem = Form.Item;
const Option = Select.Option;
const dateFormat = 'YYYY-MM-DD';
var _ = require( 'underscore');
class _Modal extends Component {
  constructor(props) {
    super(props);
    this.state = {
      visible: false,
      mes:'',
      name:'',
      address:'',
      customer_num:'',
      record:props.record ||{contract_num:''}
    };
  }

  showModelHandler =async (e) => {
    if (e) e.stopPropagation();
      this.setState({
        visible: true,
        mes:'',
        name:'',
        address:'',
        customer_num:''
      });
  }

  hideModelHandler = () => {
    this.setState({
      visible: false,
        mes:'',
        name:'',
        address:'',
        customer_num:''
    });
    this.props.form.resetFields()
  };
  handleSubmit = async(e) => {
      let values = this.props.form.getFieldsValue()
      let item = Object.assign({}, values);
      let res = await  StockModel.getByNum(this.props.stock.cnum)
      let item1=_.extend(res.data.item,item);
      item1.status="waitSendInput";
      await StockModel.updateByNum(this.props.stock.cnum,item1)
      this.hideModelHandler()
      this.props.updateList()
  };
  onChange=(date, dateString)=>{
  console.log(date, dateString);
}
  render() {
    const { children } = this.props;
    const { getFieldDecorator,getFieldValue} = this.props.form;
    const formItemLayout = {
      labelCol: { span: 6 },
      wrapperCol: { span: 14 },
    };
    return (
      <span>
        <span onClick={this.showModelHandler}>
          { children }
        </span>
        <Modal
          title={'编辑货运信息'}
          visible={this.state.visible}
          onCancel={this.hideModelHandler}
          onOk={this.handleSubmit}
          width="60%"
        >
            <Form layout="horizontal" >
                  <FormItem className={styles.FormItem} {...formItemLayout} label="pi号" >
                    {getFieldDecorator('product_identity',
                    {initialValue: this.state.record.product_identity,rules: [{required: true, message: '必须填写'}]})
                    (<Input size="small" />)  }
                  </FormItem>
            </Form>
        </Modal>
      </span>
    );
  }
}

export default Form.create()(_Modal);
